<?php
session_start();

$col=':';
$dbuser=$_SESSION['dbuser'];
$dbpass=$_SESSION['dbpass'];
$dbport=$_SESSION['dbport'];
$dbhost=$_SESSION['dbhost'];
$dbname=$_SESSION['dbname'];

$showusname = $_POST["username"];

if ($dbhost=="localhost") {
   $dbhost = "127.0.0.1";
   } 

$dbhostport = $dbhost . $col . $dbport ; 

$con = mysql_connect($dbhostport, $dbuser, $dbpass);
if (!$con)
    {
      $error=mysql_error();
      $_SESSION['error'] = $error;
      
      Header("Location: error.php");
    }
  
mysql_select_db($dbname, $con);

if ((!isset($_POST['submit_show_user_entries'])) && (!isset($_POST['submit_show_full_user_entries'])) && (!isset($_POST['submit_clone_user'])) && (!isset($_POST['submit_rename_user'])) && (!isset($_POST['submit_set_password']))) { // if page is not submitted to itself echo the form

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><HEAD><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>Sam-My - Securich GUI tool - User Accounts</TITLE>

	<STYLE type="text/css" media="all">
	
	body {
		background: #f70;
		font: 0.8em arial, helvetica, sans-serif;
		margin: 0;
		padding: 0;
		height:100%;
        padding-bottom:35px;   /* Height of the footer */
	}
	
	#footer {
        position: absolute;
 	    bottom: 40px;
	    width:100%;
	    height:15px;   /* Height of the footer */
	    color: #FFF;
    }
	
	#header {
		background-color: white;
	}
	
    #header ul {
		list-style: none;
		padding: 0;
		margin: 0;
		background: white;
		float: left;
		width: 100%;
    }
    
	#header li {
		float: left;
		margin: 0 1em 0 0;
    }
    
	#header a {
		text-decoration: none;
		display: block;
		width: 6em;
		padding: 0 0.5em;
		font-weight: bold;
		color: black;
		border-bottom: 0.5em solid #fc6;
		color: #fc6;
    }
	
	#header a:hover {
		color: #fa3;
		border-color: #fa3;
	}
	
	#header #selected a {
		color: #f80;
		border-color: #f80;
	}
	
	#content {
        position:absolute;
        top: 85px;
        left:60px;
		clear: both;
		color: white;
		padding: 1em;
	}
	
	#content p {
		margin: 0 0 1em 0;
	}
	
	h1 {
		margin: 0;
		padding: 0.5em 0 1em 0.5em;
		color: #f80;
		font-size: 1.5em;
		font-style: italic;
	}

	</STYLE>
	
</HEAD>
<BODY>

<DIV id="header">

<H1>Sam-My - The GUI frontend for Securich, the security plugin for MySQL</H1>

<UL>
	<LI><A href="welcome.php">Home</A></LI>
	<LI id="selected"><A href="accounts.php">Accounts</A></LI>
	<LI><A href="grant_revoke.php">Privileges</A></LI>
	<LI><A href="configure.php">Config</A></LI>
	<LI><A href="securich.php">Securich</A></LI>
	<LI><A href="help.php">Help</A></LI>
	<LI><A href="logout.php">Log Out</A></LI>
</UL>
</DIV>

<DIV id="content">
<FORM METHOD='post' ACTION='"<?php echo $PHP_SELF;?>"'>
<table>  
  <tr>
    <td colspan="3">
      <br><br><br><b>User Accounts:</b><br><br>
    </td>
  </tr>
  <tr>
    <td width="10px"></td>
    <td></td>
    <td>
    <div align='left' style="
         position:relative;
         left:12px;
         z-index:1;
         overflow:auto;
         margin-right:6px;
 		 width:450px;
		 height:407px">
		 <table>
		   <tr>
		     <td width='10px'>&nbsp;
               
		     </td>
		     <td>&nbsp;
		       
		     </td>
		     <td width='5px'>&nbsp;
		       
		     </td>
		     <td align='left'>
		       Username
		     </td>
		     <td width='15px'>&nbsp;
		       
		     </td>
		     <td align='left'>
		       Hostname
		     </td>
		     <td>
        
             <?
	 	       $result = mysql_query("select us.USERNAME, ho.HOSTNAME 
	 	                         from sec_us_ho usho join sec_users us join sec_hosts ho
                                 where usho.US_ID=us.ID and usho.HO_ID=ho.ID order by 1 asc");
                                 
               $totalaccounts=mysql_query("select count(*) from sec_users");

               while($row = mysql_fetch_array($result))
               {
                 echo "<tr>";
                 echo "<td>&nbsp;</td>";
                 echo "<td align='left	'><input type='radio' name='username' value='" . $row['USERNAME'] . ":" . $row['HOSTNAME'] . "'></td>"; 
                 echo "<td width='5px'>&nbsp;</td>";
                 echo "<td align='left'>" . $row['USERNAME'] . "</td>";
                 echo "<td width='35px'>&nbsp;</td>";
                 echo "<td align='left'>" . $row['HOSTNAME'] . "</td>";
                 echo "</tr>";
               }
             ?>
             </td>
           </tr>
         </table>
    </div><br>
    </td>
    <td width='80px'>&nbsp;</td>
    <td valign='top'> 
        <div align='left' style="
         position:relative;
         left:12px;
         font-size: 12px;
         top: 25px;
         z-index:1;">
		 <table>
		   <tr>
		     <td align='left'>
               <b>Commands:</b><br>
		     </td>
		   </tr>
		   <tr>
		     <td align='right'>
		       <input type="submit" value="Clone User" name="submit_clone_user"><br>
		       <input type="submit" value="Rename User" name="submit_rename_user"><br>
		       <input type="submit" value="Set Password" name="submit_set_password"><br><br><br>
		     </td>
		   </tr>
		   <tr>
		     <td align='left'>
               <b>Show:</b><br>
		     </td>
		   </tr>
		   <tr>
		     <td align='right'>
		       <input type="submit" value="Show User Entries" name="submit_show_user_entries"><br>
		       <input type="submit" value="Show Full User Entries" name="submit_show_full_user_entries">
		     </td>
		   </tr>		   
		   <tr><td><br></td></tr>
		   <tr>
		     <td>
				&nbsp;
		     </td>
		   </tr>
		 </table>  
		</div>
    </td>
  </tr><br><br>
</table>
</FORM>
</DIV>
 
   <DIV id="footer" align="left">
   <table>
     <tr>
       <td width="23px">&nbsp;</td>
       <td>
         Copyright &copy; Darren Cassar a.k.a. preacher<br />
         Developed by Darren Cassar <?php echo date("Y"); ?> - GPLv2
       </td>
     </tr>
   </table>
   </DIV>
   
<?
} else { 

  list($selected_username, $selected_hostname) = explode(":" , $showusname);

  if (isset($_POST['submit_clone_user'])) {
    $_SESSION['showusname'] = $selected_username;
    $_SESSION['showhtname'] = $selected_hostname;

    Header("Location: clone_user.php");
  }
  
  if (isset($_POST['submit_rename_user'])) {
    $_SESSION['showusname'] = $selected_username;
    $_SESSION['showhtname'] = $selected_hostname;

    Header("Location: rename_user.php");
  }
  
  if (isset($_POST['submit_set_password'])) {
    $_SESSION['showusname'] = $selected_username;
    $_SESSION['showhtname'] = $selected_hostname;
    
    Header("Location: set_password.php");
  }
  
  if (isset($_POST['submit_show_user_entries'])) 
  {
    $_SESSION['showusname'] = $selected_username;

    Header("Location: show_user_entries.php");
  }
  
  if (isset($_POST['submit_show_full_user_entries'])) {
    $_SESSION['showusname'] = $selected_username;

    Header("Location: show_full_user_entries.php");
  }
  
} // end if  

?>

</BODY></HTML>